﻿using CrateMayhem.Common.ViewModel;
using Windows.UI.Core;
using GameControlViewModel = CrateMayhem.WinRT.ViewModel.GameControlViewModel;

namespace CrateMayhem.WinRT
{
    public sealed partial class GameControls
    {
        private readonly GameControlViewModel model;

        public GameControls()
        {
            InitializeComponent();
            
            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                model = (GameControlViewModel)Global.Container.Resolve<ViewModelBase>(typeof(GameControlViewModel).Name);
                DataContext = model;
                CoreWindow.GetForCurrentThread().KeyDown += OnKeyDown;
            }
        }

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            model.PerformKeyPress(e.VirtualKey);
        }
    }
}
